package com.example.common.dto;

import lombok.Data;

/**
 * 响应实体
 *
 * @author cui haida
 * @version JDK 8
 * 2025/8/4
 */
@Data
public class Result<T> {
    private int code;
    private String message;
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setMessage("success");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(int code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> unauthorized(String message) {
        return error(401, message);
    }
}